import os
import time
import sys

data = " int main(){ \n" \
       " printf('123')\n" \
       "return 0;\n" \
       "}"

dict = []
for i in range(len(data)):
    dict.append(data[i])
#print(dict)

key = ['int', 'double', 'float', 'main', 'delete', 'return', 'printf']
operator = ['+', '-', '*', '/', ';', '{', '}', '"', "'", '(', ")"]

def is_num(a):
    try:
        num = int(a)
        return True
    except:
        return False


class lexAnalyzer:
    def __init__(self):
        self.status = 0
        self.token = ""
        self.last_status = 0
        self.index = 0
        self.times = 0
        self.data = []

    def process(self):
        #print(dict[self.index])
        if dict[self.index] == '\n':
            self.index = self.index +1
            self.status = 0
            return
        if dict[self.index] == ' ':
            self.status = 0
            self.index = self.index + 1
            return
        else:
            try:
                num = int(dict[self.index])
                self.token = self.token + dict[self.index]
                self.index += 1
                self.last_status = self.status
                self.status = 3
                return
            except:
                pass
            temp = dict[self.index]
            if temp in operator:
                self.status = 5
                self.token = self.token + temp
                self.last_status = 0
                self.index += 1
                return
            else:
                self.index = self.index + 1
                self.token = self.token + temp
                self.status = 2
                self.last_status = 0
                return

    def process1(self):
        temp = dict[self.index]
        if temp == '\n' or temp == ' ':
            print({
                self.token:1
            })
            self.token = ""
            self.index += 1
            self.status = 0
            self.last_status = 1
            self.times = 0
            return
        if temp not in operator:
            self.token += temp
            self.index += 1
            self.status = 2
            self.last_status = 1
            self.times = 0
        else:
            print({
                self.token:1
            })
            self.token = temp
            self.index += 1
            self.times = 0
            self.status = 5
            self.last_status =1
            return

    def process2(self):
        temp = dict[self.index]
        if temp == '\n' or temp == ' ':
            self.index += 1
            print({
                self.token:2
            })
            self.token = ""
            self.status = 0
            self.last_status = 2
            self.times = 0
            return
        if is_num(temp):
            self.token += temp
            self.index += 1
            self.times += 1
        elif temp in operator:
            print({
                self.token:2
            })
            self.token = temp
            self.status = 5
            self.last_status = 2
            self.times = 0
            self.index += 1
        else:
            self.token += temp
            if self.token not in key:
                self.index += 1
                #self.token += temp
                self.times += 1
            else:
                self.index += 1
                self.status = 1
                self.last_status = 2
                self.times = 0

    def process3(self):
        temp = dict[self.index]
        # print(temp)
        if temp == '\n' or temp == ' ':
            self.index += 1
            self.status = 0
            self.last_status = 3
            self.times = 0
            print({
                self.token:3
            })
            self.token = ""
            return
        else:
            if is_num(temp):
                self.index += 1
                self.times += 1
                self.token += temp
            elif temp in operator:
                print({
                    self.token:3
                })
                self.token = temp
                self.status = 5
                self.last_status = 3
                self.times = 0
                self.index += 1
            else:
                self.token += temp
                self.status = 2
                self.last_status = 3
                self.times = 0
                self.index += 1
        return

    def process5(self):
        temp = dict[self.index]
        if temp == ' ' or temp == '\n':
            print({
                self.token:5
            })
            self.index += 1
            self.status = 0
            self.last_status = 5
            self.times = 0
            self.token = ''
        else:
            print({
                self.token:5
            })
            if is_num(temp):
                self.token = temp
                self.index += 1
                self.last_status = 5
                self.times = 0
                self.status = 3
            elif temp in operator:
                self.token = temp
                self.index += 1
            else:
                self.token = temp
                self.index += 1
                self.last_status = 5
                self.times = 0
                self.status = 2
        return






analyzer = lexAnalyzer()
while(analyzer.index<len(dict)):
    temp_status = analyzer.status
    #print({
    #    "temp_status":temp_status
    # })

    if temp_status == 0:
        analyzer.process()
    elif temp_status == 1:
        analyzer.process1()
    elif temp_status == 2:
        analyzer.process2()
    elif temp_status == 3:
        analyzer.process3()
    elif temp_status == 5:
        analyzer.process5()
    else:
        print("error")






